﻿using System;
using System.Xml;
using System.Collections;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Services;
using System.Data;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string ValidaUsuario(string XMLUsuario) {
        string result = "";
        string ruta2 = "c:\\TEMP\\archivo.txt";
        StreamWriter escritor2 = new StreamWriter(ruta2, true);
        
        escritor2.Close();
        try
        {
           
          
            RE_User usuariovalidar = utility2.PharseXML(XMLUsuario);
          
            RE_User usuariovalido = DB2.ValidaCliente(usuariovalidar.userID, usuariovalidar.pss, usuariovalidar.appl, usuariovalidar.perfil);
            result="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            result += "<datos_respuesta>";
            if (usuariovalido != null)
            {
                result += "<respuestaid>1</respuestaid>";// 0=false 1=true
                result += "<usuarioid>"+usuariovalido.userID+"</usuarioid>";
                result += "<nombre>"+usuariovalido.nombre+"</nombre>";
                result += "<apellido>"+usuariovalido.apellido+"</apellido>";
                result += "<alias>"+usuariovalido.alias+"</alias>";
                result += "<perfilid>"+usuariovalido.perfil+"</perfilid>";
                result += "<group>" + usuariovalido.group + "</group>";
                result += "<permiso>"+usuariovalido.permiso+"</permiso>";
                result += "<logo>" + usuariovalido.logo + "</logo>";
                result += "<where>" + usuariovalido.where + "</where>";
                result += "<where2>" + usuariovalido.where2 + "</where2>";
                result += "<permisouser>" + usuariovalido.permisouser + "</permisouser>";
                result += "<restricted>" + usuariovalido.restricted + "</restricted>";

            }
            else {
                result += "<respuestaid>0</respuestaid>";// 0=false 1=true
                result += "<usuarioid></usuarioid>";
                result += "<nombre></nombre>";
                result += "<apellido></apellido>";
                result += "<alias></alias>";
                result += "<perfilid></perfilid>";
                result += "<group></group>";
                result += "<permiso></permiso>";
                result += "<logo></logo>";
                result += "<where></where>";
                result += "<where2></where2>";
                result += "<permisouser></permisouser>";
                result += "<restricted></restricted>";
            }
	        
            result += "</datos_respuesta>";
        }
        catch (Exception e) {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString()+"  "+e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
      
        return result;
    }

    [WebMethod]
    public string RegistraUsuario(string XMLUsuario)
    {
        string result = "";
        try
        {
            RE_User usuario = utility2.PharseXML_Registro(XMLUsuario);
            bool insertado = DB2.InsertarCliente(usuario);
            usuario = DB2.ValidaCliente(usuario.userID, usuario.pss, usuario.appl, usuario.perfil);
            result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; 
            result += "<datos_respuesta>";
            if (insertado)
            {
                result += "<respuestaid>1</respuestaid>";// 0=false 1=true
                result += "<usuarioid>" + usuario.userID + "</usuarioid>";
                result += "<nombre>" + usuario.nombre + "</nombre>";
                result += "<apellido>" + usuario.apellido + "</apellido>";
                result += "<alias>" + usuario.alias + "</alias>";
                result += "<perfilid>" + usuario.perfil + "</perfilid>";
                result += "<group>" + usuario.group + "</group>";
                result += "<permiso>" + usuario.permiso + "</permiso>";
                result += "<logo>"+ usuario.logo+"</logo>";
                if (usuario.group.ToUpper() == "CLIENT")
                {
                    RE_GenericBean2 acc = new RE_GenericBean2();
                    acc.strC1 = utility2.toCapital(usuario.nombre).Trim() + " " + utility2.toCapital(usuario.apellido).Trim();
                    acc.strC2 = usuario.alias;
                    acc.intC1 = 1;
                    bool inAcc = DB2.InsertarAccount(acc);
                    ArrayList views = DB2.getUsuariosbyPerfil(1);
                    //configurando las ordenes que puede ver en WK de clientes
                    if (views != null)
                    {
                        foreach (RE_User userAux in views)
                        {
                            string where = "";
                            int c = 0;
                            where = " and ( ";
                            foreach (RE_User users in views)
                            {
                                if (userAux.userID == users.userID)
                                {
                                    if (c == 1) { where += " and "; } else { c = 1; }
                                    where += " client_id = '" + users.userID.Trim() + "' ";
                                }
                            }
                            where += " ) ";
                            if (where.Equals(" and (  ) ")) where = "";
                            int res = DB2.updatedata("tbl_usuario", "usu_where", "usu_id", userAux.userID.ToUpper(), 0, where, 0, 1);
                        }
                    }

                    //agregando precios default a cliente
                    DataSet ds = DB2.getDefaultProducts();
                    string [][] matvprices= new string[50][];
                   
                    for (int k = 0;k < ds.Tables[0].Rows.Count; k++ ) {
                         matvprices[k] = new string[2];
                         matvprices[k][0] = ds.Tables[0].Rows[k][0].ToString();
                         matvprices[k][1] = ds.Tables[0].Rows[k][4].ToString();
                    
                    }
                    DB2.setPrecioporUsuario(usuario.userID, matvprices, ds.Tables[0].Rows.Count);
                }
            }
            else
            {
                result += "<respuestaid>0</respuestaid>";// 0=false 1=true
                result += "<usuarioid></usuarioid>";
                result += "<nombre></nombre>";
                result += "<apellido></apellido>";
                result += "<alias></alias>";
                result += "<perfilid></perfilid>";
                result += "<group></group>";
                result += "<permiso></permiso>";
                result += "<logo></logo>";
            }

            result += "</datos_respuesta>";
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getDatosUsuario(string userID)
    {
        string result = "";
        try
        {
            RE_User usuario = DB2.getUsuariosData(userID,0);

            if (usuario != null)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>1</respuestaid>";
                result += "<user>" + usuario.userID + "</user>";
                result += "<pass>" + usuario.pss + "</pass>";
                result += "<nombre>" + usuario.nombre + "</nombre>";
                result += "<apellido>" + usuario.apellido + "</apellido>";
                result += "<comp-name>" + usuario.compania + "</comp-name>";
                result += "<alias>" + usuario.alias + "</alias>";
                result += "<email>" + usuario.email + "</email>";
                result += "<title>" + usuario.title + "</title>";
                result += "<estado>" + usuario.estado + "</estado>";
                result += "<aplicacionid>" + usuario.appl + "</aplicacionid>";
                result += "<perfilid>" + usuario.perfil + "</perfilid>";
                result += "<existe>" + usuario.existe + "</existe>";
                result += "<where1>"+usuario.where +"</where1>";
                result += "<where2>" + usuario.where2 + "</where2>";
                result += "<restricted>" + usuario.restricted + "</restricted>";
                result += "<permiso>" + usuario.permisouser + "</permiso>";
                result += "<permiso>" + usuario.permiso + "</permiso>";
                result += "<permiso>" + usuario.where3 + "</permiso>";
                result += "<restrictedrol>" + usuario.restrictedrol + "</restrictedrol>";
                result += "<direcciones>";
                foreach (RE_Direccion direccion in usuario.direcciones)
                {
                    result += "<direccion>";
                    result += "<uidID>" + direccion.uinID + "</uidID>";
                    result += "<add1>" + direccion.stnumber + "</add1>";
                    result += "<add2>" + direccion.stadd + "</add2>";
                    result += "<city>" + direccion.city + "</city>";
                    result += "<state>" + direccion.state + "</state>";
                    result += "<zip>" + direccion.zip + "</zip>";
                    result += "<office_phone>" + direccion.telof + "</office_phone>";
                    result += "<cell_phone>" + direccion.telcel + "</cell_phone>";
                    result += "<fax>" + direccion.fax + "</fax>";
                    result += "<tipo>" + direccion.tipodir + "</tipo>";
                    result += "<credit_card>";
                    foreach (RE_CreditCard tarjeta in direccion.tarjetas)
                    {
                        result += "<tacID>" + tarjeta.tacID + "</tacID>";
                        result += "<namecreditcard>" + tarjeta.name + "</namecreditcard>";
                        result += "<creditcard>" + tarjeta.number + "</creditcard>";
                        result += "<expdate>" + tarjeta.expdate + "</expdate>";
                        result += "<ccv>" + tarjeta.ccv + "</ccv>";
                    }
                    result += "</credit_card>";
                    result += "</direccion>";
                }
                result += "</direcciones>";
               
                result += "</datos_registro>";
            }
            else {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>0</respuestaid>";
                result += "</datos_registro>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getDatosUsuarioAlias(string userAlias)
    {
        string result = "";
        try
        {
            RE_User usuario = DB2.getUsuariosData(userAlias,1);

            if (usuario != null)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>1</respuestaid>";
                result += "<user>" + usuario.userID + "</user>";
                result += "<pass>" + usuario.pss + "</pass>";
                result += "<nombre>" + usuario.nombre + "</nombre>";
                result += "<apellido>" + usuario.apellido + "</apellido>";
                result += "<comp-name>" + usuario.compania + "</comp-name>";
                result += "<alias>" + usuario.alias + "</alias>";
                result += "<email>" + usuario.email + "</email>";
                result += "<title>" + usuario.title + "</title>";
                result += "<estado>" + usuario.estado + "</estado>";
                result += "<aplicacionid>" + usuario.appl + "</aplicacionid>";
                result += "<perfilid>" + usuario.perfil + "</perfilid>";
                result += "<existe>" + usuario.existe + "</existe>";
                result += "<where1>" + usuario.where + "</where1>";
                result += "<where2>" + usuario.where2 + "</where2>";
                result += "<restricted>" + usuario.restricted + "</restricted>";
                result += "<permiso>" + usuario.permisouser + "</permiso>";
                result += "<permiso>" + usuario.permiso + "</permiso>";
                result += "<permiso>" + usuario.where3 + "</permiso>";
                result += "<restrictedrol>" + usuario.restrictedrol + "</restrictedrol>";
                result += "<direcciones>";
                foreach (RE_Direccion direccion in usuario.direcciones)
                {
                    result += "<direccion>";
                    result += "<uidID>" + direccion.uinID + "</uidID>";
                    result += "<add1>" + direccion.stnumber + "</add1>";
                    result += "<add2>" + direccion.stadd + "</add2>";
                    result += "<city>" + direccion.city + "</city>";
                    result += "<state>" + direccion.state + "</state>";
                    result += "<zip>" + direccion.zip + "</zip>";
                    result += "<office_phone>" + direccion.telof + "</office_phone>";
                    result += "<cell_phone>" + direccion.telcel + "</cell_phone>";
                    result += "<fax>" + direccion.fax + "</fax>";
                    result += "<tipo>" + direccion.tipodir + "</tipo>";
                    result += "<credit_card>";
                    foreach (RE_CreditCard tarjeta in direccion.tarjetas)
                    {
                        result += "<tacID>" + tarjeta.tacID + "</tacID>";
                        result += "<namecreditcard>" + tarjeta.name + "</namecreditcard>";
                        result += "<creditcard>" + tarjeta.number + "</creditcard>";
                        result += "<expdate>" + tarjeta.expdate + "</expdate>";
                        result += "<ccv>" + tarjeta.ccv + "</ccv>";
                    }
                    result += "</credit_card>";
                    result += "</direccion>";
                }
                result += "</direcciones>";

                result += "</datos_registro>";
            }
            else
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>0</respuestaid>";
                result += "</datos_registro>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getTodosDatosUsuario(string userID)
    {
        string result = "";
        try
        {
            RE_User usuario = DB2.getUsuariosData(userID,0);

            if (usuario != null)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>1</respuestaid>";
                result += "<usuarioid>" + usuario.userID + "</usuarioid>";
                result += "<pass>" + usuario.pss + "</pass>";
                result += "<nombre>" + usuario.nombre + "</nombre>";
                result += "<apellido>" + usuario.apellido + "</apellido>";
                result += "<comp-name>" + usuario.compania + "</comp-name>";
                result += "<alias>" + usuario.alias + "</alias>";
                result += "<email>" + usuario.email + "</email>";
                result += "<title>" + usuario.title + "</title>";
                result += "<estado>" + usuario.estado + "</estado>";
                result += "<aplicacionid>" + usuario.appl + "</aplicacionid>";
                result += "<perfilid>" + usuario.perfil + "</perfilid>";
                result += "<group>" + usuario.group + "</group>";
                result += "<existe>" + usuario.existe + "</existe>";
                result += "<where1>" + usuario.where + "</where1>";
                result += "<where2>" + usuario.where2 + "</where2>";
                result += "<restricted>" + usuario.restricted + "</restricted>";
                result += "<permisouser>" + usuario.permisouser + "</permisouser>";
                result += "<logo>" + usuario.logo + "</logo>";
                result += "<permiso>" + usuario.permiso + "</permiso>";
                result += "<where3>" + usuario.where3 + "</where3>";
                result += "<restrictedrol>" + usuario.restrictedrol + "</restrictedrol>";

                result += "<direcciones>";
                foreach (RE_Direccion direccion in usuario.direcciones)
                {
                    result += "<direccion>";
                    result += "<uidID>" + direccion.uinID + "</uidID>";
                    result += "<add1>" + direccion.stnumber + "</add1>";
                    result += "<add2>" + direccion.stadd + "</add2>";
                    result += "<city>" + direccion.city + "</city>";
                    result += "<state>" + direccion.state + "</state>";
                    result += "<zip>" + direccion.zip + "</zip>";
                    result += "<office_phone>" + direccion.telof + "</office_phone>";
                    result += "<cell_phone>" + direccion.telcel + "</cell_phone>";
                    result += "<fax>" + direccion.fax + "</fax>";
                    result += "<tipo>" + direccion.tipodir + "</tipo>";
                    result += "<credit_card>";
                    foreach (RE_CreditCard tarjeta in direccion.tarjetas)
                    {
                        result += "<tacID>" + tarjeta.tacID + "</tacID>";
                        result += "<namecreditcard>" + tarjeta.name + "</namecreditcard>";
                        result += "<creditcard>" + tarjeta.number + "</creditcard>";
                        result += "<expdate>" + tarjeta.expdate + "</expdate>";
                        result += "<ccv>" + tarjeta.ccv + "</ccv>";
                    }
                    result += "</credit_card>";
                    result += "</direccion>";
                }
                result += "</direcciones>";
                result += "<companies>";
                foreach (RE_GenericBean2 company in usuario.companies)
                {
                    result += "<company>";
                    result += "<id>" + company.intC1 + "</id><nombre>" + company.strC1 + "</nombre>";
                    result += "</company>";

                }
                result += "</companies>";

                result += "<accounts>";
                foreach (RE_GenericBean2 acc in usuario.accounts)
                {
                    result += "<account>";
                    result += "<id>" + acc.intC1 + "</id><nombre>" + acc.strC1 + "</nombre>";
                    result += "</account>";

                }
                result += "</accounts>";

                result += "<states>";
                foreach (RE_GenericBean2 state in usuario.states)
                {
                    result += "<state>";
                    result += "<id>" + state.intC1 + "</id>";
                    result += "</state>";

                }
                result += "</states>";

                result += "<counties>";
                foreach (RE_GenericBean2 county in usuario.counties)
                {
                    result += "<county>";
                    result += "<id>" + county.intC1 + "</id>";
                    result += "</county>";

                }
                result += "</counties>";

                result += "<perfiles>";
                foreach (RE_GenericBean2 perfil in usuario.perfiles)
                {
                    result += "<perfil>";
                    result += "<id>" + perfil.intC1 + "</id><nombre>" + perfil.strC1 + "</nombre>";
                    result += "</perfil>";

                }
                result += "</perfiles>";

                result += "<prices>";
                foreach (RE_GenericBean2 price in usuario.prices)
                {
                    result += "<price>";
                    result += "<product_id>" + price.intC1 + "</product_id><price>" + price.strC1 + "</price>";
                    result += "</price>";

                }
                result += "</prices>";
                
                result += "<permisos>";
                foreach (RE_GenericBean2 permiso in usuario.permisos)
                {
                    result += "<permiso>";
                    result += "<usuID>" + permiso.strC1 + "</usuID>";
                    result += "<pageID>" + permiso.intC1 + "</pageID>";
                    result += "<permit>" + permiso.int64C1 + "</permit>";
                    result += "<restricted>" + permiso.int64C2 + "</restricted>";
                    result += "</permiso>";
                }
                result += "</permisos>";
                result += "</datos_registro>";
            }
            else
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>0</respuestaid>";
                result += "</datos_registro>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getTodosDatosUsuarioAlias(string userID)
    {
        string result = "";
        try
        {
            RE_User usuario = DB2.getUsuariosData(userID, 1);

            if (usuario != null)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>1</respuestaid>";
                result += "<usuarioid>" + usuario.userID + "</usuarioid>";
                result += "<pass>" + usuario.pss + "</pass>";
                result += "<nombre>" + usuario.nombre + "</nombre>";
                result += "<apellido>" + usuario.apellido + "</apellido>";
                result += "<comp-name>" + usuario.compania + "</comp-name>";
                result += "<alias>" + usuario.alias + "</alias>";
                result += "<email>" + usuario.email + "</email>";
                result += "<title>" + usuario.title + "</title>";
                result += "<estado>" + usuario.estado + "</estado>";
                result += "<aplicacionid>" + usuario.appl + "</aplicacionid>";
                result += "<perfilid>" + usuario.perfil + "</perfilid>";
                result += "<existe>" + usuario.existe + "</existe>";
                result += "<where1>" + usuario.where + "</where1>";
                result += "<where2>" + usuario.where2 + "</where2>";
                result += "<restricted>" + usuario.restricted + "</restricted>";
                result += "<permisouser>" + usuario.permisouser + "</permisouser>";
                result += "<logo>" + usuario.logo + "</logo>";
                result += "<permiso>" + usuario.permiso + "</permiso>";
                result += "<where3>" + usuario.where3 + "</where3>";
                result += "<restrictedrol>" + usuario.restrictedrol + "</restrictedrol>";

                result += "<direcciones>";
                foreach (RE_Direccion direccion in usuario.direcciones)
                {
                    result += "<direccion>";
                    result += "<uidID>" + direccion.uinID + "</uidID>";
                    result += "<add1>" + direccion.stnumber + "</add1>";
                    result += "<add2>" + direccion.stadd + "</add2>";
                    result += "<city>" + direccion.city + "</city>";
                    result += "<state>" + direccion.state + "</state>";
                    result += "<zip>" + direccion.zip + "</zip>";
                    result += "<office_phone>" + direccion.telof + "</office_phone>";
                    result += "<cell_phone>" + direccion.telcel + "</cell_phone>";
                    result += "<fax>" + direccion.fax + "</fax>";
                    result += "<tipo>" + direccion.tipodir + "</tipo>";
                    result += "<credit_card>";
                    foreach (RE_CreditCard tarjeta in direccion.tarjetas)
                    {
                        result += "<tacID>" + tarjeta.tacID + "</tacID>";
                        result += "<namecreditcard>" + tarjeta.name + "</namecreditcard>";
                        result += "<creditcard>" + tarjeta.number + "</creditcard>";
                        result += "<expdate>" + tarjeta.expdate + "</expdate>";
                        result += "<ccv>" + tarjeta.ccv + "</ccv>";
                    }
                    result += "</credit_card>";
                    result += "</direccion>";
                }
                result += "</direcciones>";
                result += "<companies>";
                foreach (RE_GenericBean2 company in usuario.companies)
                {
                    result += "<company>";
                    result += "<id>" + company.intC1 + "</id><nombre>" + company.strC1 + "</nombre>";
                    result += "</company>";

                }
                result += "</companies>";

                result += "<accounts>";
                foreach (RE_GenericBean2 acc in usuario.accounts)
                {
                    result += "<account>";
                    result += "<id>" + acc.intC1 + "</id><nombre>" + acc.strC1 + "</nombre>";
                    result += "</account>";

                }
                result += "</accounts>";

                result += "<states>";
                foreach (RE_GenericBean2 state in usuario.states)
                {
                    result += "<state>";
                    result += "<id>" + state.intC1 + "</id>";
                    result += "</state>";

                }
                result += "</states>";

                result += "<counties>";
                foreach (RE_GenericBean2 county in usuario.counties)
                {
                    result += "<county>";
                    result += "<id>" + county.intC1 + "</id>";
                    result += "</county>";

                }
                result += "</counties>";

                result += "<perfiles>";
                foreach (RE_GenericBean2 perfil in usuario.perfiles)
                {
                    result += "<perfil>";
                    result += "<id>" + perfil.intC1 + "</id><nombre>" + perfil.strC1 + "</nombre>";
                    result += "</perfil>";

                }
                result += "</perfiles>";

                result += "<prices>";
                foreach (RE_GenericBean2 price in usuario.prices)
                {
                    result += "<price>";
                    result += "<product_id>" + price.intC1 + "</product_id><price>" + price.strC1 + "</price>";
                    result += "</price>";

                }
                result += "</prices>";

                result += "<permisos>";
                foreach (RE_GenericBean2 permiso in usuario.permisos)
                {
                    result += "<permiso>";
                    result += "<usuID>" + permiso.strC1 + "</usuID>";
                    result += "<pageID>" + permiso.intC1 + "</pageID>";
                    result += "<permit>" + permiso.int64C1 + "</permit>";
                    result += "<restricted>" + permiso.int64C2 + "</restricted>";
                    result += "</permiso>";
                }
                result += "</permisos>";

                result += "</datos_registro>";
            }
            else
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<datos_registro>";
                result += "<respuestaid>0</respuestaid>";
                result += "</datos_registro>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string UsuariosPorPerfil(int perfilID)
    {
        string result = "";
        try
        {
            ArrayList usuarios = DB2.getUsuariosbyPerfil(perfilID);

            if (usuarios != null && usuarios.Count>0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_usuarios>";
                foreach (RE_User usuario in usuarios)
                {
                    
                    result += "<datos_registro>";
                    result += "<user>" + usuario.userID + "</user>";
                    result += "<name>" + usuario.nombre + "</name>";
                    result += "<lastname>" + usuario.apellido + "</lastname>";
                    result += "<comp-name>" + usuario.compania + "</comp-name>";
                    result += "<alias>" + usuario.alias + "</alias>";
                    result += "<email>" + usuario.email + "</email>";
                    result += "<profile>"+perfilID + "</profile>";
                    result += "<profilename>" + usuario.perfil + "</profilename>";
                    string group = "";
                    switch ( perfilID){
                        case 1: group = "Client"; break;
                        case 2: group = "Vendor"; break;
                        case 3: group = "Employee"; break;
                        case 4: group = "Employee"; break;
                        case 5: group = "Employee"; break;
                        case 6: group = "Employee"; break;
                        case 7: group = "Employee"; break;
                        case 8: group = "Employee"; break;
                        case 9: group = "Employee"; break;
                        case 10: group = "Employee"; break;
                        case 11: group = "Employee"; break;
                        case 12: group = "Employee"; break;
                        case 13: group = "Employee"; break;
                        case 20: group = "Employee"; break;
                        case 21: group = "Employee"; break;
                        case 22: group = "Employee"; break;
                        case 23: group = "Employee"; break;
                        case 24: group = "Employee"; break;
                        case 26: group = "Employee"; break;
                        default: group = "Employee"; break;
                    }
                   
                    result += "<group>" + group + "</group>";

                    result += "</datos_registro>";
                }
                result += "</lista_usuarios>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getPerfiles(int catalogo, int app)
    {
        string result = "";
        try
        {
            ArrayList perfiles = DB2.getPerfilesbyApp(catalogo, app);

            if (perfiles != null && perfiles.Count > 0)
            {
                //result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result = "<lista_perfiles>";
                foreach (RE_GenericBean2 perfil in perfiles)
                {

                    result += "<perfil>";
                    result += "<perfilID>" + perfil.intC1 + "</perfilID>";
                    result += "<perfilNombre>" + perfil.strC1 + "</perfilNombre>";
                    result += "</perfil>";
                }
                result += "</lista_perfiles>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string getPerfilesPermiso(int catalogo)
    {
        string result = "";
        try
        {
            ArrayList perfiles = DB2.getPerfilesPermiso(catalogo);

            if (perfiles != null && perfiles.Count > 0)
            {
                //result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result = "<lista_perfiles>";
                foreach (RE_GenericBean2 perfil in perfiles)
                {
                    result += "<perfil>";
                    result += "<perfilID>" + perfil.intC1 + "</perfilID>";
                    result += "<perfilNombre>" + perfil.strC1 + "</perfilNombre>";
                    result += "<perfilPermiso>" + perfil.int64C1 + "</perfilPermiso>";
                    result += "<perfilRestricted>" + perfil.int64C2 + "</perfilRestricted>";
                    result += "<perfilPagina>" + perfil.intC2 + "</perfilPagina>";
                    result += "</perfil>";
                }
                result += "</lista_perfiles>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string ActivateUser(string UserID)
    {
        string result = "0";
        try
        {
            bool respueta= DB2.ActivateUser(UserID);

            if (respueta)
            {
                result = "1";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }
     [WebMethod]
    public string DesactivateUser(string UserID)
    {
        string result = "0";
        try
        {
            bool respueta = DB2.DesactivateUser(UserID);

            if (respueta)
            {
                result = "1";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
    public string setLogoUser(string XMLUsuarioLogo)
    {
        string result="0";
        try {
            bool respuesta = DB2.setLogoUser(XMLUsuarioLogo);
            if (respuesta)
            {
                result = "1";
            }
        
        }
        catch (Exception e) {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            
        
        }


        return result;

    }

    [WebMethod]
    public string getCompanies()
    {
        string result = "";
        try
        {
            ArrayList companies = DB2.getCompanies();

            if (companies != null && companies.Count > 0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_companies>";
                foreach (RE_GenericBean2 company in companies)
                {

                    result += "<datos_company>";
                    result += "<com_id>" + company.intC1 + "</com_id>";
                    company.strC1= company.strC1.Replace("&", "&amp;");
                    result += "<com_nombre>" + company.strC1 + "</com_nombre>";
                    company.strC2= company.strC2.Replace("&", "&amp;");
                    result += "<com_url>" + company.strC2 + "</com_url>";
                    company.strC3=company.strC3.Replace("&", "&amp;");
                    result += "<com_contacts>" + company.strC3 + "</com_contacts>";
                    company.strC4=company.strC4.Replace("&", "&amp;");
                    result += "<com_phone>" + company.strC4 + "</com_phone>";
                    result += "</datos_company>";
                }
                result += "</lista_companies>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }


    [WebMethod]
    public string getAccounts()
    {
        string result = "";
        try
        {
            ArrayList account = DB2.getAccounts();

            if (account != null && account.Count > 0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_account>";
                foreach (RE_GenericBean2 acc in account)
                {

                    result += "<datos_account>";
                    result += "<acc_id>" + acc.intC1 + "</acc_id>";
                    result += "<acc_nombre>" + acc.strC1 + "</acc_nombre>";
                    result += "<acc_initial>"+acc.strC2+"</acc_initial>";
                    result += "</datos_account>";
                }
                result += "</lista_account>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }
     [WebMethod]
    public string getCompany(string comp)
    {
        string result = "";
        try
        {
            ArrayList company = DB2.getCompany(comp);

            if (company != null && company.Count > 0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_companies>";
                foreach (RE_GenericBean2 compa in company)
                {

                    result += "<datos_company>";
                    result += "<com_id>" + compa.intC1 + "</com_id>";
                    result += "<com_nombre>" + compa.strC1 + "</com_nombre>";
                    result += "</datos_company>";
                }
                result += "</lista_companies>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

    [WebMethod]
     public string getAccount(string acco)
     {
         string result = "";
         try
         {
             ArrayList account = DB2.getAccount(acco);

             if (account != null && account.Count > 0)
             {
                 result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                 result += "<lista_account>";
                 foreach (RE_GenericBean2 acc in account)
                 {

                     result += "<datos_account>";
                     result += "<acc_id>" + acc.intC1 + "</acc_id>";
                     result += "<acc_nombre>" + acc.strC1 + "</acc_nombre>";
                     result += "<acc_initial>" + acc.strC2 + "</acc_initial>";
                     result += "</datos_account>";
                 }
                 result += "</lista_account>";
             }
         }
         catch (Exception e)
         {
             string ruta = "c:\\TEMP\\archivo.txt";
             StreamWriter escritor = new StreamWriter(ruta, true);
             escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
             escritor.Close();
             return null;
         }
         return result;
     }
    [WebMethod]
    public string getOpcionApp(int app_id)
    {
        string result = "";
        try
        {
            ArrayList opcion = DB2.getOpcionApp(app_id);

            if (opcion != null && opcion.Count > 0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_opciones>";
                foreach (RE_GenericBean2 acc in opcion)
                {

                    result += "<opcion>";
                    result += "<oap_id>" + acc.intC1 + "</oap_id>";
                    result += "<oap_nombre>" + acc.strC1 + "</oap_nombre>";
                    result += "<oap_permiso>" + acc.int64C1 + "</oap_permiso>";
                    result += "</opcion>";
                }
                result += "</lista_opciones>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }
    [WebMethod]
    public int RegistraCompany(string XMLCompany)
    {
        int result = 0;
        try
        {
            //string smlx = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <datos_registro><name>otracomp</name><estado>1</estado></datos_registro>";
            RE_GenericBean2 company = utility2.PharseXML_Company(XMLCompany);
            //RE_GenericBean2 company = utility2.PharseXML_Company(smlx);
            bool insertado = DB2.InsertarCompany(company);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }

            
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;
    }
    [WebMethod]
    public int RegistraAccount(string XMLAccount)
    {
        int result = 0;
        try
        {
            RE_GenericBean2 account = utility2.PharseXML_Account(XMLAccount);
            bool insertado = DB2.InsertarAccount(account);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }


        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;
    }
    [WebMethod]
    public int RegistraTypeEmployee(string XMLEmployee)
    {
        int result = 0;
        try
        {
            RE_GenericBean2 Temployee = utility2.PharseXML_TEmployee(XMLEmployee);
            bool insertado = DB2.InsertarTEmployee(Temployee);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }


        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;
    }
    [WebMethod]
    public int setDataUser(string XMLDATA)
    {
        int result = 0;
       // string sxml = "<?xml version=\"1.0\" encoding=\"utf8\"?><data><userid>LUCIANAB</userid><group>3</group><perfiles><perfil>7 </perfil></perfiles><CompanyAccess><company>1 </company><company>8 </company><company>14 </company><company>21</company></CompanyAccess><OptionsAccess><option>1048576 </option><option>4096 </option><option>524288 </option><option>8192 </option><option>131072 </option><option>2097152 </option><option>512 </option></OptionsAccess><ViewDefault><view>FIVESTAR </view></ViewDefault><RestrictedAccess><option>1048576 </option><option>262144 </option><option>4096 </option><option>524288 </option><option>8192 </option><option>131072 </option><option>2097152 </option><option>512</option></RestrictedAccess><FilterView></FilterView><ClientCompanies><company>1 </company><company>2 </company><company>3 </company><company>4 </company></ClientCompanies><ClientAccounts><account>1 </account><account>2 </account><account>3 </account><account>4</account></ClientAccounts><VendorStates><state>4</state><state>17</state><state>32</state><state>53</state></VendorStates><VendorCounties><county>378</county><county>379</county><county>30</county><county>32</county><county>42</county><county>47</county><county>358</county><county>359</county><county>395</county><county>158</county></VendorCounties><ClientPrices><product>6</product><price>5.00 </price><product>7</product><price>10.00 </price><product>1</product><price>15.00 </price></ClientPrices><VendorPrices><product>3</product><price>5.00 </price><product>2</product><price>10.00 </price><product>7</product><price>15.00 </price></VendorPrices></data>";
        string sxml = "";
        result=utility2.PharseXML_UserData(XMLDATA);
        //result = utility2.PharseXML_UserData(sxml);

        return result;
    }
    [WebMethod]
    public int updateDataPerfil(string XMLDATA)
    {
        int result = 0;
        string sxml = "";

         
        result=utility2.PharseXML_PerfilData(XMLDATA);

        //result = utility2.PharseXML_PerfilData(sxml);

        return result;
    }
    [WebMethod]
    public int registraPerfil(string XMLDATA) {
        int result = 0;
        try
        {
            
            RE_GenericBean2 perfil = utility2.PharseXML_NewPerfil(XMLDATA);
            bool insertado = DB2.InsertarPerfil(perfil);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }


        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;
    
    }
    [WebMethod]
    public int registraPage(string XMLDATA)
    {
        int result = 0;
        try
        {
            // string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <role><name>PROCESSOR JUNIOR</name><permiso>640</permiso><app>1</app></role>";
           // string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <opcion><name>OPCION1</name><permiso>4194304</permiso><app>1</app></opcion>";
            RE_GenericBean2 opcion = utility2.PharseXML_NewPage(XMLDATA);
            bool insertado = DB2.InsertarPage(opcion);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }


        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;

    }
    [WebMethod]
    public int updateDataPage(string XMLDATA)
    {
        int result = 0;

        string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><data><opcionid>10</opcionid><app>1</app><OptionsAccess><option>1048576 </option><option>524288 </option><option>2 </option><option>65536 </option></OptionsAccess></data>";
        result = utility2.PharseXML_PageData(XMLDATA);
        //result = utility2.PharseXML_OpcionData(sxml);

        return result;
    }

    [WebMethod]
    public int deletePerfil(string rolID)
    {
        int result = 0; int result2 = 0; int resulttotal = 0;

        result = DB2.delete("tbl_perfil", "per_id", rolID, 0, 1);
        result2 = DB2.delete("tbl_perfil_aplicacion", "ape_per_id", rolID, 0, 1);
        if (result==1 && result2==1){
            resulttotal = 1;
        }
        return resulttotal;
    }

    [WebMethod]
    public int deletePage(string XMLDATA, int app)
    {
        int result = 0; int result2 = 0; int resulttotal = 0;
        try
        {
            
            int id = int.Parse(XMLDATA);
            result = DB2.deletePage(app, id);
            //result = DB2.delete("tbl_opcion_aplicacion", "oap_id", "", id, 0);
            //result = utility2.PharseXML_OpcionData(sxml);
            if (result == 1)
            {
                resulttotal = 1;
            }
        }catch(Exception e){
            resulttotal = 0;
        }
        return resulttotal;
    }
    
    [WebMethod]
    public string getPerfilPerRes(int Per, string App)
    {
      
        string ruta = "c:\\TEMP\\archivo.txt";
        StreamWriter escritor = new StreamWriter(ruta, true);
        escritor.WriteLine("***** getPErfilPErREs recibe *"+ Per);
        escritor.Close();


        ArrayList res = null; string result=null;
        try
        {

            int id = int.Parse(App);


            res = DB2.getPerfilPerRes(Per, App);
            if (res!=null){

                //result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result = "<lista_pageopp_permisos>";
                foreach (RE_GenericBean2 per in res)
                {
                    result += "<perfil>";
                    result += "<idperfil>" + per.intC1 + "</idperfil>";
                    result += "<idpage>" + per.intC2 + "</idpage>";
                    result += "<permiso>" + per.int64C1 + "</permiso>";
                    result += "<restricted>" + per.int64C2 + "</restricted>";
                    result += "</perfil>";
                }
                result += "</lista_pageopp_permisos>";
            }
            
        }
        catch (Exception e)
        {
            
        }
        return result;
    }
    [WebMethod]
        public string getAppPages(int app)
        {
            string res = null; string result = null;
            try
            {

                int id = app;


                res = DB2.getPages(app);
                if (res == null)
                {
                    res = "";
                  
                }

            }
            catch (Exception e)
            {

            }
            return res;
        }
    [WebMethod]
    public string getAppOptions(int page)
    {
        string res = null; string result = null;
        try
        {

            int id = page;


            res = DB2.getOpcionbyPage(page);
            if (res == null)
            {
                res = "";

            }

        }
        catch (Exception e)
        {

        }
        return res;
    }

    [WebMethod]
    public int deleteOption(string pid, string parent)
    {
        int result = 0; int result2 = 0; int resulttotal = 0;
        try
        {

            int id = int.Parse(pid);
            result = DB2.deleteOption(id, parent);
            //result = DB2.delete("tbl_opcion_aplicacion", "oap_id", "", id, 0);
            //result = utility2.PharseXML_OpcionData(sxml);
            if (result == 1)
            {
                resulttotal = 1;
            }
        }
        catch (Exception e)
        {
            resulttotal = 0;
        }
        return resulttotal;
    }

    [WebMethod]
    public int registraOption(string XMLDATA)
    {
        int result = 0;
        try
        {
            // string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <role><name>PROCESSOR JUNIOR</name><permiso>640</permiso><app>1</app></role>";
            // string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <opcion><name>OPCION1</name><permiso>4194304</permiso><app>1</app></opcion>";
            RE_GenericBean2 opcion = utility2.PharseXML_NewOption(XMLDATA);
            bool insertado = DB2.InsertarOption(opcion);
            result = 0;
            if (insertado)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }


        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return 0;
        }
        return result;

    }
    [WebMethod]
    public int updateDataOption(string XMLDATA)
    {
        int result = 0;

        string sxml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><data><opcionid>10</opcionid><app>1</app><OptionsAccess><option>1048576 </option><option>524288 </option><option>2 </option><option>65536 </option></OptionsAccess></data>";
        result = utility2.PharseXML_UpdateOpcion(XMLDATA);
        //result = utility2.PharseXML_OpcionData(sxml);

        return result;
    }

    [WebMethod]
    public int updateDataMenu(string XMLDATA)
    {
        int result = 0;
        result = utility2.PharseXML_UpdateMenu(XMLDATA);

        return result;
    }

    [WebMethod]
    public int deleteDataMenu(string XMLDATA)
    {
        int result = 0;
        result = utility2.PharseXML_DeleteMenu(XMLDATA);
        return result;
    }

    [WebMethod]
    public int addDataMenu(string XMLDATA)
    {
        int result = 0;
        result = utility2.PharseXML_AddMenu(XMLDATA);
        return result;
    }

    [WebMethod]
    public string getClientProductFee(string CLIENTID, string PRODUCTID) {
        string result = "";
        result = DB2.clientProductFee(CLIENTID, PRODUCTID);

        return result;
    }
    
 [WebMethod]
    public string getUserbystatus(int value)
    {
        string result = "";
        try
        {
            ArrayList usuarios = DB2.getInactiveUsers(value);

            if (usuarios != null && usuarios.Count>0)
            {
                result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                result += "<lista_usuarios>";
                foreach (RE_User usuario in usuarios)
                {
                    int perfilID = 0;
                    result += "<datos_registro>";
                    result += "<user>" + usuario.userID + "</user>";
                    result += "<name>" + usuario.nombre + "</name>";
                    result += "<lastname>" + usuario.apellido + "</lastname>";
                    result += "<comp-name>" + usuario.compania + "</comp-name>";
                    result += "<alias>" + usuario.alias + "</alias>";
                    result += "<email>" + usuario.email + "</email>";
                    result += "<profile>"+usuario.existe + "</profile>";
                    result += "<profilename>" + usuario.perfil + "</profilename>";
                    string group = "";

                   
                    if (usuario.existe != 0) {
                        perfilID = usuario.existe;
                        switch (perfilID)
                        {
                            case 1: group = "Client"; break;
                            case 2: group = "Vendor"; break;
                            case 3: group = "Employee"; break;
                            case 4: group = "Employee"; break;
                            case 5: group = "Employee"; break;
                            case 6: group = "Employee"; break;
                            case 7: group = "Employee"; break;
                            case 8: group = "Employee"; break;
                            case 9: group = "Employee"; break;
                            case 10: group = "Employee"; break;
                            case 11: group = "Employee"; break;
                            case 12: group = "Employee"; break;
                            case 13: group = "Employee"; break;
                            case 20: group = "Employee"; break;
                            case 21: group = "Employee"; break;
                            case 22: group = "Employee"; break;
                            case 23: group = "Employee"; break;
                            case 24: group = "Employee"; break;
                            case 26: group = "Employee"; break;
                            default: group = "Employee"; break;
                        }
                    }
                   
                   
                    result += "<group>" + group + "</group>";

                    result += "</datos_registro>";
                }
                result += "</lista_usuarios>";
            }
        }
        catch (Exception e)
        {
            string ruta = "c:\\TEMP\\archivo.txt";
            StreamWriter escritor = new StreamWriter(ruta, true);
            escritor.WriteLine(e.Message.ToString() + "  " + e.StackTrace.ToString());
            escritor.Close();
            return null;
        }
        return result;
    }

 [WebMethod]
 public string getMenus(int app, int menu)
 {
     string res = null; 
     try
     {
         int id = app;
         res = DB2.getMenus(app, menu);
         if (res == null)
         {
             res = "";
         }
     }
     catch (Exception e) { }
     return res;
 }

[WebMethod]
 public string getPagesView(int app)
 {
     string res = null;
     try
     {
         int id = app;
         res = DB2.getPagesView(app);
         if (res == null)
         {
             res = "";
         }
     }
     catch (Exception e) { }
     return res;
 }

[WebMethod]
public string setPaypalPaid(string xml)
{
    string res = null;
    try
    {
        string ruta = "c:\\TEMP\\archivoPaypal.txt";
        StreamWriter escritor = new StreamWriter(ruta, true);
        escritor.WriteLine("PaypalPaid: "+xml);
        escritor.Close();
        return null;
    }
    catch (Exception e) { }
    return res;
}

}